package com.jiepos.mpos.pay;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.jiepos.mpos.core.util.StringUtils;

/**
 * 
 * 
 * <p>标题: —— 定时任务查询异步通知失败的流水</p>
 * <p>模块: 通用平台</p>
 * <p>版权: Copyright (c) 2017 江苏杰博实信息技术有限公司
 * @ProjectName:  [mpos] 
 * @Package com.jiepos.mpos.pay 
 * @author 张学涛
 * @version 1.0
 * @since 2018年3月6日上午10:11:00
 * @history（历次修订内容、修订人、修订时间等）
 */
public class MsgNotifyQueryService {
	
	private static final Logger _log = LoggerFactory.getLogger(MsgNotifyQueryService.class);
	
	@Autowired
	private AppLogTransJnlsPayService appLogTransJnlsPayService;
	@Autowired
	private MainBusinessService mainBusinessService;
	
	public void process() {
		_log.info("定时任务查询异步通知失败的流水开始:");
		List<Map<String, String>> list = appLogTransJnlsPayService.getNotifyFailList();
		if (!StringUtils.isEmpty(list) && !list.isEmpty()) {
			_log.info("异步通知失败的流水[{}]",list);
			int size = list.size();
			for (int i = 0; i < size; i++) {
				queryService(list.get(i));
			}
		}else{
			_log.warn("定时任务查询异步通知失败的流水无符合条件记录!");
		}
		_log.info("定时任务查询异步通知失败的流水结束!");
		
	}
	
	private void queryService(Map<String, String> reqMap) {
		try {
			mainBusinessService.msgNotify(reqMap);
		} catch (Exception e) {			
			_log.error("流水号[{}]异步通知发生异常",reqMap.get("loc_trace_no"), e);
		}
	}

}
